const mysql = require('mysql2');
import level from './level';

const datas = level.map((data: any) => {
  return {
    level: data.Id,
    exp: data.Exp,
  };
});

const connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: 'Winzhao@919',
  database: 'xxsg_db',
});

connection.connect((err: any) => {
  if (err) {
    console.log(err);
    return;
  }

  console.log('数据库连接成功');
  const insertQuery = 'INSERT INTO config_exp (id, exp) VALUES ?';

  connection.query(
    insertQuery,
    [datas.map((data: any) => Object.values(data))],
    (err: any, result: { affectedRows: any }) => {
      if (err) {
        console.error('插入数据失败:', err);
        return;
      }

      console.log(`插入 ${result.affectedRows} 条数据.`);
    },
  );

  // 关闭连接
  connection.end();
});
